{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ultralytics import YOLO\n",
    "\n",
    "# Initialize a YOLO-World model\n",
    "model = YOLO(\"yolov8l-world.pt\")  # or choose yolov8m/l-world.pt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "image 1/1 /home/minhducnguyen/WORK/ComfyUI/custom_nodes/ComfyUI-YoloWorld-EfficientSAM/manycups.jpg: 384x640 4 there is 3 cups in the image, detect the cup at the left mosts, 43.9ms\n",
      "Speed: 5.3ms preprocess, 43.9ms inference, 2.7ms postprocess per image at shape (1, 3, 384, 640)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "perl: warning: Setting locale failed.\n",
      "perl: warning: Please check that your locale settings:\n",
      "\tLANGUAGE = (unset),\n",
      "\tLC_ALL = (unset),\n",
      "\tLC_TIME = \"vi_VN\",\n",
      "\tLC_MONETARY = \"vi_VN\",\n",
      "\tLC_ADDRESS = \"vi_VN\",\n",
      "\tLC_TELEPHONE = \"vi_VN\",\n",
      "\tLC_NAME = \"vi_VN\",\n",
      "\tLC_MEASUREMENT = \"vi_VN\",\n",
      "\tLC_IDENTIFICATION = \"vi_VN\",\n",
      "\tLC_NUMERIC = \"vi_VN\",\n",
      "\tLC_PAPER = \"vi_VN\",\n",
      "\tLANG = \"en_US.UTF-8\"\n",
      "    are supported and installed on your system.\n",
      "perl: warning: Falling back to a fallback locale (\"en_US.UTF-8\").\n"
     ]
    }
   ],
   "source": [
    "# Define custom classes\n",
    "model.set_classes([\"there is 3 cups in the image, detect the cup at the left most\"])\n",
    "\n",
    "# Execute prediction for specified categories on an image\n",
    "results = model.predict(\"manycups.jpg\")\n",
    "\n",
    "# Show results\n",
    "results[0].show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "perl: warning: Setting locale failed.\n",
      "perl: warning: Please check that your locale settings:\n",
      "\tLANGUAGE = (unset),\n",
      "\tLC_ALL = (unset),\n",
      "\tLC_TIME = \"vi_VN\",\n",
      "\tLC_MONETARY = \"vi_VN\",\n",
      "\tLC_ADDRESS = \"vi_VN\",\n",
      "\tLC_TELEPHONE = \"vi_VN\",\n",
      "\tLC_NAME = \"vi_VN\",\n",
      "\tLC_MEASUREMENT = \"vi_VN\",\n",
      "\tLC_IDENTIFICATION = \"vi_VN\",\n",
      "\tLC_NUMERIC = \"vi_VN\",\n",
      "\tLC_PAPER = \"vi_VN\",\n",
      "\tLANG = \"en_US.UTF-8\"\n",
      "    are supported and installed on your system.\n",
      "perl: warning: Falling back to a fallback locale (\"en_US.UTF-8\").\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating inference sessions\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "UserWarning: Specified provider 'OpenVINOExecutionProvider' is not in available provider names.Available providers: 'TensorrtExecutionProvider, CUDAExecutionProvider, AzureExecutionProvider, CPUExecutionProvider'\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CLIP model loaded in 2.09 seconds\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[0;93m2024-08-22 12:23:42.474786966 [W:onnxruntime:, transformer_memcpy.cc:74 ApplyImpl] 3 Memcpy nodes are added to the graph torch_jit for CUDAExecutionProvider. It might have negative impact on performance (including unable to run CUDA graph). Set session_options.log_severity_level=1 to see the detail logs before this message.\u001b[m\n"
     ]
    }
   ],
   "source": [
    "from inference.models import YOLOWorld\n",
    "YOLO_WORLD_MODEL = YOLOWorld(model_id=\"yolo_world/l\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "YOLO_WORLD_MODEL.set_classes('person')\n",
    "results = YOLO_WORLD_MODEL.infer(\"holland_.jpg\", confidence=0.001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ObjectDetectionInferenceResponse(visualization=None, frame_id=None, time=1.3525681463070214, image=InferenceResponseImage(width=1500, height=1000), predictions=[])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "comfyui_clone",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
